<?php

class Bootstrap
	extends Zend_Application_Bootstrap_Bootstrap {

    public function _initRegistryVariable() {
	$config = new Zend_Config($this->_options);
	Zend_Registry::set('config', $config);
    }

    public function _initDatabase() {
	$this->bootstrap('db');
	$db = $this->getResource('db');
	Zend_Registry::set('db', $db);
    }

    public function _initZFDebug() {
	if ($this->_options['ZFDebug']) {
	    $this->bootstrap('db');
	    $db = $this->getResource('db');
	    $options = array(
		'plugins' => array(
		    'Html',
		    'Variables',
		    'File' => array(APPLICATION_PATH),
		    'Memory',
		    'Time',
		    'Registry',
		    'Exception',
		    'Database' => array(
			'adapter' => $db
		    )
		)
	    );

	    $debug = new ZFDebug_Controller_Plugin_Debug($options);
	    $this->bootstrap('frontController');
	    $frontController = $this->getResource('frontController');
	    $frontController->registerPlugin($debug);
	}
    }

    public function _initAuth() {
	$auth = Zend_Auth::getInstance();
	$auth->setStorage(new Zend_Auth_Storage_Session());
	$this->bootstrap('frontController');
	$frontController = $this->getResource('frontController');
	$frontController->registerPlugin(new Extends_Controller_Plugin_AclManager($auth));
    }

    public function _initLogger() {
	$logger = new Extends_Log($this->_options['debug']['activation']);
	$logger->addWriter(new Zend_Log_Writer_Firebug());
	$logger->addWriter(new Zend_Log_Writer_Stream($this->_options['logger']['file']));
	Zend_Registry::set('logger', $logger);
    }

    public function _initRewrite() {
	$this->bootstrap('frontController');
	$frontController = $this->getResource('frontController');
	$router = $frontController->getRouter();
	include_once APPLICATION_PATH . '/config/routes.php';
	$frontController->setBaseUrl('/')->setRouter($router);
    }

    public function  _bootstrap($resource = null) {
	parent::_bootstrap($resource);

	$view = new Extends_View();
	$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
            'ViewRenderer'
        );
        $viewRenderer->setView($view);
    }

}
